package com.pinda.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pinda.auth.search.PdCommonLoginLogSearch;
import com.pinda.commonutils.Page;
import com.pinda.commonutils.Result;
import com.pinda.commonutils.StatusCode;
import com.pinda.auth.entity.PdCommonLoginLog;
import com.pinda.service.IPdCommonLoginLogService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 登录日志 前端控制器
 * </p>
 *
 * @author 黄杰
 * @since 2023-06-13
 */
@RestController
@RequestMapping("/pd_common_login_log")
public class PdCommonLoginLogController {
    @Resource
    private IPdCommonLoginLogService iPdCommonLoginLogService;

    /**
     * TODO 分页条件查询登入日志
     * @return List<PdCommonLoginLog>
     */
    @RequestMapping("/findLoginLog")
    public Result<PageInfo<PdCommonLoginLog>> findLoginLog(@RequestBody Page<PdCommonLoginLogSearch> page){
        return new Result<PageInfo<PdCommonLoginLog>>(true, StatusCode.OK, "查询成功",this.iPdCommonLoginLogService.findLoginLogService(page));
    }

    /**
     * 根据用户编号查询该用户的登录记录
     * @return
     */
    @GetMapping("/queryloginhistory/{id}")
    public Result<List<PdCommonLoginLog>> queryloginhistory(@PathVariable("id") long id){
        PageHelper.startPage(1,5);
        PageHelper.orderBy("id DESC");
        QueryWrapper<PdCommonLoginLog> q=new QueryWrapper<>();
        q.eq("user_id",id);
        List<PdCommonLoginLog> list = this.iPdCommonLoginLogService.list(q);
        return new Result<>(true,StatusCode.OK,"查询成功",list);
    }
}
